//
//  FeedbackVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/5/10.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "FeedbackVC.h"
#import "QXTextView.h"

@interface FeedbackVC ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet QXTextView *textContent;
//@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIButton *btnSubmit;
@property (nonatomic ,strong) NSMutableArray  *imageArr;
@end

@implementation FeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"设置";
    
    self.hidesBottomBarWhenPushed = YES;
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:0 target:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
    self.btnSubmit.layer.masksToBounds=YES;
    self.btnSubmit.layer.cornerRadius=5.0;
    
    self.textContent.textColor=DEFAULTTEXTGRAYCOLOR;
    self.textContent.delegate=self;
}

- (void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- 修改头像
- (void)updateHead{
    UIAlertController *alertCtrl=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];;
    UIAlertAction *albumAction=[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        UIImagePickerController * ipc = [[UIImagePickerController alloc] init];
        ipc.delegate = self;
        ipc.allowsEditing=YES;
        ipc.sourceType = sourceType;
        [self presentViewController:ipc animated:YES completion:nil];
    }];
    UIAlertAction *cameraAction=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
        UIImagePickerController * ipc = [[UIImagePickerController alloc] init];
        ipc.delegate = self;
        ipc.allowsEditing=YES;
        ipc.sourceType = sourceType;
        [self presentViewController:ipc animated:YES completion:nil];
    }];
    [alertCtrl addAction:cancleAction];
    [alertCtrl addAction:albumAction];
    [alertCtrl addAction:cameraAction];
    [self presentViewController:alertCtrl animated:YES completion:nil];
}



- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [BaseVM manage].viewCtrl=self;
}

#pragma mark -- UINavigationControllerDelegate, UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    [[BaseVM manage] postImageWithImage:image andType:2 andSuccess:^(id returnValue) {
        [SVProgressHUD showSuccessWithStatus:@"头像修改成功"];
        [UserInfoModel share].Avater=[returnValue objectForKey:@"Url"];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}


- (NSMutableArray *)imageArr{
    if (!_imageArr) {
        _imageArr=[[NSMutableArray alloc]init];
    }
    return _imageArr;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
